package com.nl.controller.web.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nl.controller.common.annotation.SystemServiceLog;
import com.nl.controller.common.exception.SmsException;
import com.nl.controller.common.service.CommonService;
import com.nl.controller.common.util.DateUtils;
import com.nl.controller.web.bean.SmsFied;
import com.nl.controller.web.mapper.SmsFiedMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class SmsFiedService {
    @Autowired
    private SmsFiedMapper smsFiedMapper;

    @Autowired
    private CommonService commonService;

    @SystemServiceLog(description = "外来人数统计", value = false)
    public PageInfo<SmsFied> countFied
            (int page, int limit,String cityId,String mgrId,String regionId,String stationId,String way,String month,String startTime,String endTime) {
        PageHelper.startPage(page, limit);
        List<SmsFied> list=new ArrayList();
        Map<String,Object> map=new HashMap();
        map.put("cityId",cityId);
        map.put("mgrId",mgrId);
        map.put("regionId",regionId);
        map.put("stationId",stationId);
        if("0".equals(way)){
            map.put("startTime", month+"01");
            map.put("endTime", DateUtils.getLastDayOfMonth(month));
        }else {
            map.put("startTime",startTime);
            map.put("endTime",endTime);
        }
        try {
            list=smsFiedMapper.countFied(map);
        }catch (Exception e) {
            e.printStackTrace();
            log.error("统计外来用户");
            throw new SmsException("统计外来用户");
        }
        PageInfo<SmsFied> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }
}
